package com.yangjian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yangjian.bean.SetmealDish;
import com.yangjian.dao.SetmealDishDao;
import com.yangjian.service.SetmealDishService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SetmealDishServiceImpl implements SetmealDishService {

    @Autowired
    private SetmealDishDao dao;


    /**
     * 添加套餐的菜品
     *
     * @param setmealDish
     * @return
     */
    @Override
    public int add(SetmealDish setmealDish) {

        int row = dao.insert(setmealDish);

        return row;
    }

    /**
     * 根据套餐的id来查套餐菜品表的菜品
     *
     * @param sid
     * @return
     */
    @Override
    public List<SetmealDish> select(long sid) {

        LambdaQueryWrapper<SetmealDish> lqw  = new LambdaQueryWrapper<>();
        lqw.eq(SetmealDish::getSetmealId,sid);
        List<SetmealDish> setmealDishes = dao.selectList(lqw);
        return setmealDishes;
    }

    /**
     * 根据套餐的id来删除套餐菜品表的菜品
     *
     * @param sid
     * @return
     */
    @Override
    public int delete(long sid) {

        LambdaQueryWrapper<SetmealDish> lqw  = new LambdaQueryWrapper<>();
        lqw.eq(SetmealDish::getSetmealId,sid);
        int row = dao.delete(lqw);
        return row;
    }
}
